<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-28 22:51:19
 * @lastTime 2020-04-28 22:57:31
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Design\Behavioral\Memento;

class Ticket
{

    private $currentState;


    public function __construct()
    {
        $this->currentState = new State(State::STATE_CREATED);

    }//end __construct()


    public function open()
    {
        $this->currentState = new State(State::STATE_OPENED);

    }//end open()


    public function assign()
    {
        $this->currentState = new State(State::STATE_ASSIGNED);

    }//end assign()


    public function close()
    {
        $this->currentState = new State(State::STATE_CLOSED);

    }//end close()


    public function saveToMemento() : Memento
    {
        return new Memento(clone $this->currentState);

    }//end saveToMemento()


    public function restoreFromMemento(Memento $memento)
    {
        $this->currentState = $memento->getState();

    }//end restoreFromMemento()


    public function getState() : State
    {
        return $this->currentState;

    }//end getState()


}//end class
